package com.jyniubi.core.controller.api;


import com.jyniubi.base.result.R;
import com.jyniubi.base.utils.JwtUtils;
import com.jyniubi.core.pojo.entity.BorrowInfo;
import com.jyniubi.core.service.BorrowInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author jyzhang
 * @since 2024-04-27
 */

@Api(tags = "借款申请审核模块")
@RestController
@RequestMapping("/api/core/borrowInfo")
public class ApiBorrowInfoController {
    @Resource
    private BorrowInfoService borrowInfoService;

    @ApiOperation("提交借款申请")
    @PostMapping("/auth/saveBorrowInfo")
    public R saveBorrowInfo(@RequestBody BorrowInfo borrowInfo,
                            @RequestHeader(value = "token",required = false) String token){
        Long userId = JwtUtils.getUserId(token);
        borrowInfoService.saveBorrowInfo(borrowInfo,userId);
        return R.ok();
    }

    @ApiOperation("查询借款审核状态")
    @GetMapping("/auth/getBorrowStatus")
    public R getBorrowStatus(@RequestHeader(value = "token",required = false) String token){
        Long userId = JwtUtils.getUserId(token);
        Integer status = borrowInfoService.getBorrowStatus(userId);
        return R.ok().data("status",status);
    }
}

